const { User } = require('../../model/user');
const bcrypt = require('bcrypt');
module.exports = async(req, res, next) => {
    let user = await User.findOne({ _id: req.query.id });
    let {
        userName,
        email,
        role,
        state,
    } = req.body
    let isValid = await bcrypt.compare(req.body.password, user.password);
    // res.send(password)
    if (isValid) {
        await User.updateOne({ _id: req.query.id }, {
            userName,
            email,
            role,
            state
        });
        res.redirect('/admin/user');
    } else {
        // res.render('admin/user-edit', { err: '密码输入不正确' });
        next(JSON.stringify({ path: '/admin/user-edit', id: req.query.id, message: '密码错误,不能修改用户信息' }));
    }
}